|
|
|
|
|
|
|
Option Explicit
Private Declare Function RegCloseKey Lib "advapi32.dll" _
(ByVal hKey As Long) As Long
Private Declare Function RegOpenKeyEx Lib "advapi32.dll" _
Alias "RegOpenKeyExA" (ByVal hKey As Long, ByVal lpSubKey As String, _
ByVal ulOptions As Long, ByVal samDesired As Long, phkResult As Long) _
As Long
Private Const KEY_QUERY_VALUE = &H1
Private Const KEY_SET_VALUE = &H2
Private Const KEY_CREATE SUB KEY = &H4
Private Const KEY_ENUMERATE_SUB KEYS = &H8
Private Const KEY_NOTIFY = &H10
Private Const SYNCHRONIZE = &H100000
Private Const STANDARD_RIGHTS_READ = &H20000
Private Const KEY_READ = ((STANDARD_RIGHTS_READ Or _
KEY_QUERY_VALUE Or KEY_ENUMERATE_SUB_KEYS Or KEY_NOTIFY) And _
(Not SYNCHRONIZE))
Dim controlkey As String
Private Const HKEY_LOCAL_MACHINE = &H80000002
Private Sub Form_Load()
Dim rootkey As Long
Dim res As Long
controlkey = "SYSTEM/CurrentControlSet/Control"
res = RegOpenKeyEx(HKEY_LOCAL_MACHINE, controlkey, KEY_READ, 0, rootkey)
If res <> 0 Then
MsgBox "Unable to open registry key: " & GetErrorString(res)
Exit Sub
Else
MsgBox "Key opened successfully"
End If
Call RegCloseKey(rootkey)
End Sub |
|
|
|
|
|
|
|
|
The GetErrorString function can be found in the file ErrString.bas. It uses the FormatMessage function to convert an error code into a description of a system error message. |
|
|
|
|
|